#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import sys
import string
import records

#file_path = sys.argv[1]
def encode(s):
    if s is string:
        return s.encode('utf-8')
    return ''

data = []
cards = [
"e4fec3afaf430bb5fff3c71b558d623f2fafde8d095272017070400000001",
"332e6c1b5f9810932492e88108bac4e44b7a72a2095272017070400000002",
"0e8d067f0b2d4fda7e0ddd532bf40d69c4d54c94095272017070400000004",
"a9c1428d309ba476d6f4b20c249e11ea0fb96d91095272017070400000005",
"3010cd47dbdef34c98352549676bbc42b61459f9095272017070400000006",
"85dcafd82b5f7cd0eca079a9c189498e240d5b81095272017070400000008",
"184a724e1bca6620a5951ae67ee47a4a8c5ec154095272017070400000009",
"b0c85808c898cde0d4ef7452ad8b2e94b02e17fb095272017070400000010",
"778e80043f95701a16c0cb444f366216a80037f8095272017070400000011",
"348599895746b506bce330ce5e971acac21e4a83095272017070400000012",
"87aa47a9acf982d1af9b70cfb7eaa79390a151c4095272017070400000013",
"b231a592a1815252b3097b4f24c434c3137f2b3a095272017070400000014",
"fd08c9978f8b32674330acc32825f6ce77c11c80095272017070400000015",
"13edcb92989c79e0969849f16c6817a7157ab57e095272017070400000016",
"dda0f01fbf77c34eb67ebe535a5774adae29a089095272017070400000017",
"f85e7c937f2360268f696c45485e19f1b122831d095272017070400000018",
"41af5181ca7db81cf0ec480651979e56fab55899095272017070400000019",
"fe70c68694914815c5c7a458d4fa3eb1c40792a5095272017070400000020",
"5cedab16e4552d7d979a796f030748050a9164bf095272017070400000021",
"eb62b6d8cc20c3e6f79005fcdf829af07c852c1e095272017070400000022",
"0c3ea3a2f1aec76ecbb984be54f1f6eacf38e943095272017070400000023",
"074d8ba02ca6468206b203ebb4595bd20a86e027095272017070400000024",
"3aa22888a20c277ef7a00db6ebc8cf6da69cb5d4095272017070400000025",
"1d8ce709386c95bbde8751f12139e694131d3d40095272017070400000026",
"cf1427003e71aa506ba4c5c4407fe1e6169aa44e095272017070400000027",
"d4699f8fa16a9f65eb1a32913d5984b4783a9623095272017070400000028",
"86f3d07e397182a16149e394aff2923208bbeef9095272017070400000029",
"941bc694b34267c00b8e9d4bcc4c5337908b477d095272017070400000030",
"8b0e7803293be133e176c9e51b3313b71df05350095272017070400000031",
"bc16342b47626b70c6cd0a7a04c1a104c5bc0725095272017070400000032",
"dacf27771fb26b8e8e75ed0dfe9350fbb87b5e0f095272017070400000033",
"01dc3300de9aeff15ea5ea958a4853298c21fbed095272017070400000034",
"decc816cabae6846838afee731a2d2a2afc05d2b095272017070400000035",
"04b06f12250d358061d5c6beef26c58681da56c4095272017070400000036",
"38a9b988de75708818257ae784521c12d1f21a4c095272017070400000037",
"7d59b1da01f0346896e631a1e7fcf5150e408f0d095272017070400000038",
"b6ca30302c1a4054b012f29bbb6a455766c293b1095272017070400000039",
"d6fd576e181c12440160b60f11ff51cd6d3c4812095272017070400000040",
"88b1a251d2af5c19c812c47fd1f10de6a88e34fc095272017070400000041",
"23ccb5905fa49f7bc2da9bd09adb5cf4c94a251b095272017070400000042",
"9194c1e45be4e9cbe1470cd7fdfe7a6ada3533bb095272017070400000043",
"4fc40c56cfe0341b1790b5495e4ed156009cc25e095272017070400000044",
"a2521f8cafa518336faf31a30b74ec1c574e74d8095272017070400000045",
"acdc63e9acbf294408084317445b35501ea5cb45095272017070400000046",
"c77ad73787c34ed7f82e645de024ab6fa24d4004095272017070400000047",
"868908c7837a0c70ae96fab33b7c67884ef33cce095272017070400000048",
"2297220595d3ef924b2c5a8e8090dacb4ad472b6095272017070400000049",
"430d59ac85ad8554d1627b0ee1feb350fe184e51095272017070400000050",
"0a10d275abccebe4d859bd78a716fb455f1b55aa095272017070400000051",
"086a2ff0dc5aea94c3584b7a13605d464c796fd4095272017070400000052",
"8f8ef5e63cf2cbf0e4b3ac744c500a1f70facf90095272017070400000053",
"44a08b6301a812bedf41d21ef260845d2a5b0fbc095272017070400000054",
"05e7237e0a6ff30f7ab3700b9553ee6d1177394f095272017070400000055",
"8e1d2e55fcf7af7d980f2a76e30b2ab4119d2966095272017070400000056",
"a1afa78c3cf9e47bb4e48a21c313109f8339ba9e095272017070400000057",
"b0e7ed146642542dd7b549723ebdad1b1b1c6713095272017070400000058",
"7648e74093cd786fa1e4486c34ff7f55c0a90e0f095272017070400000059",
"e8614de270cdace706ed68c0aaf9d9f1e77e4ae4095272017070400000060",
"2bb957989090a4e9d7c67b61662f3da9372ff8df095272017070400000081",
"c5a9de8332db1b8dcbcbf11ef6d459d217600480095272017070400000082",
"d4347fda50db08fc100f946fe8aa2cdd95029c49095272017070400000083",
"5ea35e6497d583dce7a73ed60a346ad90f6374f4095272017070400000084",
"48784446e10630976516c1b9be1350d1958aec3e095272017070400000085",
"78aecfff5c50c2231c5d9edf656e1e08b1cc2569095272017070400000086",
"68d4cd30babd44a77574736e7ed779423c31fcd2095272017070400000087",
"910e02754e66efa18baa8572c1a9b03f66a7ea12095272017070400000088",
"35edea51fe899d75855f2d946e0ebc74595b5c2c095272017070400000089",
"ebf48554fccf20da58d3d22cd7b97266b731c984095272017070400000090",
"2ea33552a88c09c4339d79c9ed735e1fd7d7ad70095272017070400000091",
"0965ecc6bd7701031f6e3a54cc9e46a493a1636b095272017070400000092",
"17c3d2b4ed293d1a4989fa88c4f41ad643d1436b095272017070400000093",
"6d0756e4e7e30db5776f0ad1437884ed17d4c001095272017070400000094",
"5a001ecd7df232959189d6b03bad2dd106677e05095272017070400000095",
"33cf5281cce33571a36a35019654c0c219ece7de095272017070400000096",
"c74c871eb9cd4210b819729eb0bcdff0c1b5dc61095272017070400000097",
"4f6ea96b52c917fe00aca817b3e128f0d79bb539095272017070400000098",
"2c9a2be7e7ca2c0646e3011dbc856c3aab31e68c095272017070400000099",
"bbb94c7453c0797bc89f5e1c102e816b9ffb4658095272017070400000100",
"b1eac568f83f3b7b4334506405130afac853ded2095272017070400000101",
"8023ad47f04d12c8a3d76eecec6992e0b3f96713095272017070400000102",
"d1d815c257fb854c963b25d02349d26e598643f6095272017070400000103",
"54d429d974cdfd09a9302fbcb2ec89e1596899b5095272017070400000104",
"44c6c78d2f13e3239c395c7b8e3016b7ee9ce5f7095272017070400000105",
"808582301668021b24dbd28672a4c7bae7cc38f3095272017070400000106",
"72bd7b8e6306645975565e49614ea6765846bc7c095272017070400000107",
"82d2f5f82a8f368046ca8269f73097f46d024e86095272017070400000108",
"25cbc2d4deb84a4b19d7f019560043917f38e8dd095272017070400000109",
"52489ffb0651e18ed1ac5214d623ed6fd4b5aaac095272017070400000110",
]

index = 0
with records.Database('mysql+pymysql://root:P@ssw0rd@192.168.10.2:3306/makex_game?charset=utf8') as db:
    db.query('use makex_game;')
    db.query("SET NAMES 'utf8';")
    sql = "select * from members where type = 'captain' order by id;"
    rawrows = db.query(sql)
    rows=json.loads(rawrows.export('json'))
    index = 0
    for row in rows:
        r = []
        print cards
        if len(cards)>index:
            row['NFCID'] = cards[index]
            update = "update members set NFCID = '%s' where id = '%s'" % (row['NFCID'], row['id'])
            db.query(update)
        index = index+1


